// pages/more/more.js
const app = getApp()
var server = require('../../utils/server');
var WxParse = require('../../wxParse/wxParse.js');
var that
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tu: app.globalData.tupian,
    list:[],
    PageIndex:1,
    hasNext:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    that = this
    that.list(1)
  },
  list: function (PageIndex){
    var list = that.data.list
    server.requestForm(false, 'get', 'strategy', {
      page: {
        size: 5,
        index: PageIndex
      },
      sort:{
        ord:1
      },
      filter:{
        showState:1
      }
    }, function (e) {
      console.log(e)
      if(e.code == 0){
        for (let i = 0; i < e.data.items.length; i++) {
          e.data.items[i].createTime = e.data.items[i].createTime.substr(0, 10);
          list.push(e.data.items[i])
          // WxParse.wxParse('content', 'html', e.items[i].content, that, 5);
        }
        that.setData({
          list: list,
          hasNext: e.data.hasNext
        })
      }else{
        wx.showToast({
          title: res.message,
          icon: 'none',
          duration: 1000,
        });
      }

    })
  },
  strategydetails: function (e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../strategydetails/strategydetails?id=' + id,
    })
  },
  selected:function(e){
    console.log(e)
    var id = e.currentTarget.dataset.id
    var picpath = e.currentTarget.dataset.picpath
    var title = e.currentTarget.dataset.title
    wx.navigateTo({
      url: '../selected/selected?id=' + JSON.stringify(id)  + '&picpath=' + picpath + '&title=' + title,
    })
  },
  onReachBottom: function (e) {
    
    if (that.data.hasNext){
      that.setData({
        PageIndex: that.data.PageIndex + 1
      })
      that.list(that.data.PageIndex)
    }
    
  },
})